import http from '../http'

enum LOGIN_TYPE_ENUM {
  SMS_CODE = 20, // 短信验证码登录
  PWD = 10, // 密码登录
  WECHAT = 30, // 微信登录
  QQ = 31, // QQ登录
  WECHATPUBLIC = 32, // 微信公众号登录
  MINIWECHAT = 33, // 微信小程序登录
  APPLE = 35, // apple登录
  BAR_CODE_SCANNER = 50 // 扫码机登录
}

function wxMiniLogin() {
  return http.post('/auth/api/v1/auth/wxMiniLogin')
}

function wxWebLogin() {
  return http.post('/auth/api/v1/auth/wxWebLogin')
}

function login(data: any) {
  return http.post('/auth/api/v1/auth/login', data)
}

function register(data: any) {
  return http.post('/auth/api/v1/auth/register', data)
}
/**
 * 获取微信电话号码(小程序)
 * @param phone 手机号
 */
function wxUserPhoneNumber(data: any) {
  return http.post('/auth/api/v1/auth/wxUserPhoneNumber', data)
}
/**
 * 获取验证码
 * @param phone 手机号
 */
function getCode(phone: string): Promise<{ num: number }> {
  return http.get('random/code', {
    params: {
      phone
    }
  })
}
/**
 * 用户信息
 */
function userInfo(data?: any) {
  return http.get('/ups/api/v1/user/info', data)
}

function userList(data: any) {
  return http.get('/ups/api/v1/user/list', data)
}
function userInfoUpdate(data: any) {
  return http.post('/ups/api/v1/user/update', data)
}
function getShopMember(data: any) {
  return http.get('/ups/api/v1/user/role/detail/isShopMember', data)
}
function UserBindPhoneAndMerge(data: any) {
  return http.post('/ups/api/v1/user/UserBindPhoneAndMerge', data)
}
//用户门店支付密码
function updatePayPassword(data: any) {
  return http.post('/ups/api/v1/user/updatePayPassword', data)
}

// 推荐人信息
//用户门店支付密码
function getUserByInviteCode(data: any) {
  return http.get('ups/api/v1/user/getUserByInviteCode', data)
}

/**
 * 地址
 */
function getAddressList(data: any) {
  return http.get('/ups/api/v1/user/address/list', data)
}
function getAddressInfo(data: any) {
  return http.get('/ups/api/v1/user/address/info', data)
}
function updateAddressInfo(data: any) {
  return http.post('/ups/api/v1/user/address/update', data)
}
function deleteAddressInfo(data: any) {
  return http.get('/ups/api/v1/user/address/delete', data)
}
function addressAdd(data: any) {
  return http.post('/ups/api/v1/user/address/add', data)
}
function roleUpdate(data: any) {
  return http.post('/ups/api/v1/user/reserve/role/update', data)
}

/**
 * 备忘录
 * @param data
 * @returns
 */

function notesAdd(data: any) {
  return http.post('/ups/api/v1/user/notes/add', data)
}
function notesDelete(data: any) {
  return http.get('/ups/api/v1/user/notes/delete', data)
}
function notesDeleteAll() {
  return http.get('/ups/api/v1/user/notes/deleteAll')
}
function notesInfo(data: any) {
  return http.get('/ups/api/v1/user/notes/info', data)
}
function notesList(data: any) {
  return http.get('/ups/api/v1/user/notes/list', data)
}
function notesUpdate(data: any) {
  return http.post('/ups/api/v1/user/notes/update', data)
}

// 阿里云认证
function getAuthToken(data: any) {
  return http.get('/base/api/v1/phone/verify/token', data)
}
function getPhoneWithToken(data: { spToken: string }) {
  return http.get('/base/api/v1/phone/verify/phone', data)
}

// 绑定到享实惠
function innovateBind(data: {
  userId: number
  shareCode: string
  innovateType: number
  shopId: number
}) {
  console.log('绑定关系的数据==》', data)

  return http.get('/ups/api/v1/user/innovateBind', data)
}
// 获取融云token
function getRongCloudToken(userId: number) {
  return http.get('/ups/api/v1/user/getRongYunToken', { id: userId })
}

export default {
  login,
  register,
  wxMiniLogin,
  wxWebLogin,
  getCode,
  getAddressList,
  getAddressInfo,
  updateAddressInfo,
  deleteAddressInfo,
  addressAdd,
  UserBindPhoneAndMerge,
  updatePayPassword,
  getUserByInviteCode,
  userInfo,
  userList,
  userInfoUpdate,
  wxUserPhoneNumber,
  LOGIN_TYPE_ENUM,
  roleUpdate,
  getAuthToken,
  getPhoneWithToken,
  getShopMember,
  innovateBind,
  getRongCloudToken,
  notesAdd,
  notesDelete,
  notesDeleteAll,
  notesInfo,
  notesList,
  notesUpdate
}
